//
//  TKYAddProgressController.m
//  StationHouseHelper
//
//  Created by apple on 2018/5/4.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYAddProgressController.h"
#import "TKYSlider.h"
#import "TKYSelectedView.h"
#import "TKYProgessView.h"
#import "TKYRemarkView.h"
#import "TKYAddPicButton.h"
#import "KSDatePicker.h"
#import "TKYFindTreeController.h"
#import "TKYFindTreeModel.h"
#import "DAOListView.h"
#import "TKYRemarkImageView.h"
#import "ImageBrowserViewController.h"
#import "TKYFindTreeView.h"
#import "TKYSupervisionUnitsController.h"

#define NUMBERS @"0123456789\n"

@interface TKYAddProgressController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate,UITextFieldDelegate>
{
    BOOL _isSelectedCamera;// 是否选择相机
}

/**
 pickerController
 */
@property (nonatomic, strong)UIImagePickerController *pickerController;

/**
 存图片的数组
 */

@property (nonatomic, strong)NSMutableArray *imageArrM;

@property (nonatomic, strong)TKYRemarkImageView *remarkImageView;

@property (nonatomic, strong)UIScrollView *scrollV;

/**
 分部分项
 */
@property (nonatomic, strong)TKYSelectedView *subbranchView;
/**
 工序
 */
@property (nonatomic, strong)TKYSelectedView *processhView;
/**
 时间
 */
@property (nonatomic, strong)TKYSelectedView *dateView;

/**
 进度 */
@property (nonatomic, strong)TKYProgessView *progessView;

/**
 工作量
 */
@property (nonatomic, strong)TKYSelectedView *workloadView;

/**备注
 */
@property (nonatomic, strong)TKYRemarkView *remarkView;

@property (nonatomic, strong)TKYAddPicButton *addPicButtonView;

/**
 监理单位view
 */
@property (nonatomic, strong)TKYSelectedView *supervisorView;

/**
 结构树
 */
@property (nonatomic, strong)TKYFindTreeModel *findTreeModel;

/**
 工序数据
 */
@property (nonatomic, strong)NSArray <TKYProcedureModel *>*procedureS;

/**
 工序
 */
@property (nonatomic, strong) TKYProcedureModel *procedureModel;
/**
 上传参数
 */
/**
 备注
 */
@property (strong, nonatomic) NSString *remarkStr;
/**
 完成百分比
 */
@property (copy, nonatomic) NSString *percentStr;

/**
 图片数组
 */
@property (strong, nonatomic) NSMutableArray *progressImgList;

//工程量
@property (nonatomic, strong)NSString * quantityStr;

@property (nonatomic, strong)TKYFindTreeView *findTreeView;



@end

@implementation TKYAddProgressController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //[self getProcedureListData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
     //设置导航
    [self setupNavigation];
    //设置UI
    [self setUPUI];
    //[self getProcedureListData];
}

/**
 设置导航
 */
- (void)setupNavigation{
    self.navigationItem.title = @"进度填报";
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back_btn"]  style:UIBarButtonItemStylePlain target:self action:@selector(backButton:)];
    //设置导航栏文字颜色
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.navigationController.navigationBar.barTintColor = KNavColor;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStylePlain target:self action:@selector(submitButtonClick:)];
}

/**
 设置界面
 */
- (void)setUPUI{
    [self.view addSubview:self.scrollV];
    __weak typeof(self) weakSelf = self;
    //分部分项
    self.subbranchView = [[TKYSelectedView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kHeightScale *50) titleLabelText:@"分部分项" placeholderText:@"请选择" imageName:@"select_btn"];
    self.subbranchView.selectedBtnBlock = ^(UIButton *button) {
        //[weakSelf selectedSubbranchView:weakSelf.subbranchView.textField];
        NSLog(@"选择了分部分项");
        [weakSelf.view addSubview:weakSelf.findTreeView];
       

    };
    [self.scrollV addSubview:self.subbranchView];
    
    //工序
    self.processhView = [[TKYSelectedView alloc]initWithFrame:CGRectMake(0, self.subbranchView.kx_bottom, kScreenWidth, kHeightScale *50) titleLabelText:@"当前工序:" placeholderText:@"请选择" imageName:@"select_btn"];
    self.processhView.selectedBtnBlock = ^(UIButton *button) {
        if (weakSelf.findTreeModel.ifdCode.length == 0) {
            KALERTSHOW(@"提示", @"请先选择分部分项", @"确定");
        }else{
            [weakSelf showProcessDaoListView:button selectedTF:weakSelf.processhView.textField];
        }
    };
    [self.scrollV addSubview:self.processhView];
    
    //时间
    self.dateView = [[TKYSelectedView alloc]initWithFrame:CGRectMake(0, self.processhView.kx_bottom, kScreenWidth, kHeightScale *50) titleLabelText:@"工序时间:" placeholderText:@"请选择" imageName:@"select_btn"];
    self.dateView.selectedBtnBlock = ^(UIButton *button) {
        //x,y 值无效，默认是居中的
        KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 40, 300)];
        //配置中心，详情见KSDatePikcerApperance
        picker.appearance.radius = 5;
        picker.appearance.datePickerMode = UIDatePickerModeDateAndTime;
        //设置回调
        picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
            if (buttonType == KSDatePickerButtonCommit) {
                NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
                [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                weakSelf.dateView.textField.text = [formatter stringFromDate:currentDate];
                //weakSelf.dateStr = weakCell.selectedTF.text;
                //[self.dateView.textField setNeedsDisplay];
            }
        };
        // 显示
        [picker show];
       
    };
    [self.scrollV addSubview:self.dateView];
    
    //进度
    self.progessView = [[TKYProgessView alloc]initWithFrame:CGRectMake(0, self.dateView.kx_bottom, kScreenWidth, kHeightScale *50) titleLabelText:@"当前进度:" ];
    
    self.progessView.progressValue = 0;
    self.percentStr = [NSString stringWithFormat:@"%.f",self.progessView.progressValue];
    weakSelf.progessView.progressLabel.text = [NSString stringWithFormat:@"%.lf%%",self.progessView.progressValue] ;
    self.progessView.sprogressBlock = ^(UISlider *slide) {
        weakSelf.progessView.progressLabel.text = [NSString stringWithFormat:@"%.lf%%",slide.value];
        weakSelf.percentStr = [NSString stringWithFormat:@"%.lf",slide.value];
        if ([weakSelf.processhView.textField.text isEqualToString:@"灌砼"]) {
            NSString *URL = [NSString stringWithFormat:@"%@%@token=%@&flowId=%@&percent=%.lf",kProgressApiBaseUrl,kgetQuantityUrl,[[NSUserDefaults standardUserDefaults]objectForKey:kToken],weakSelf.findTreeModel.ids,slide.value];
            NSString *urlUT = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            [SVProgressHUD showWithStatus:@"正在计算工程量"];
            [KHttpRequestTool GET:urlUT parameters:nil success:^(id response) {
                NSLog(@"%@",response[@"msg"]);
                if ([response[@"code"] integerValue] == 0) {
                    NSNumber *quantity = response[@"quantity"];
                    CGFloat quantityFloat = [quantity floatValue];
                    weakSelf.workloadView.textField.text = [NSString  stringWithFormat:@"%.2f",quantityFloat];
                    weakSelf.quantityStr = [NSString  stringWithFormat:@"%.2f",quantityFloat];
                }else{
                    [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:response[@"msg"]];
                }
                [SVProgressHUD dismiss];
                
            } failure:^(NSError *error) {
                [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"网络异常"];

                NSLog(@"%@",error);
            }];
        }
    };
    
    [self.scrollV addSubview:self.progessView];
    
    //工作量
    TKYSelectedView *workloadView = [[TKYSelectedView alloc]initWithFrame:CGRectMake(0, self.progessView.kx_bottom, kScreenWidth, 0) titleLabelText:@"工作量" placeholderText:@"请输入" imageName:@""];
    workloadView.titleLabel.kx_height = 0;
    workloadView.textField.kx_height = 0;
    workloadView.line.kx_height = 0;
    workloadView.selectedBtn.hidden = YES;
    workloadView.textField.delegate = self;
    self.workloadView = workloadView;
    [self.scrollV addSubview:workloadView];
    
    //备注
    TKYRemarkView *remarkView = [[TKYRemarkView alloc]initWithFrame:CGRectMake(0, self.workloadView.kx_bottom, kScreenWidth, kHeightScale *100) titleLabelText:@"备注信息" remarkText:@""];
    remarkView.remarkTextBlock = ^(NSString *remarkText) {
        weakSelf.remarkStr = remarkText;
    };
    self.remarkView = remarkView;
    [self.scrollV addSubview:remarkView];
    
    TKYAddPicButton *addPicButtonView = [[TKYAddPicButton alloc]initWithFrame:CGRectMake(0, remarkView.kx_bottom +5, kScreenWidth, kHeightScale *40) addPicTitleText:@"补充图片" addPicButtonTitle:@""];
    addPicButtonView.addPicButtonBlock = ^(UIButton *button) {
        if (self.imageArrM.count > 2) {
            KALERTSHOW(@"提示", @"只能选择三张图片", @"确定");
            return;
        }
        [weakSelf selectedCameraOrAlbum];
    };
    self.addPicButtonView = addPicButtonView;
    [self.scrollV addSubview:addPicButtonView];
    
    //监理单位
    self.supervisorView = [[TKYSelectedView alloc]initWithFrame:CGRectMake(0, self.remarkImageView.kx_bottom +5, kScreenWidth, kHeightScale *50) titleLabelText:@"监理单位(选填)" placeholderText:@"请选择" imageName:@"select_btn"];
    self.supervisorView.selectedBtnBlock = ^(UIButton *button) {
        //跳转选择监理单位
        TKYSupervisionUnitsController *supervisionUnitsVC = [TKYSupervisionUnitsController new];
        supervisionUnitsVC.selectedSupervisionUnitsBlock = ^(NSString *supervisionUnitName) {
            weakSelf.supervisorView.textField.text = supervisionUnitName;
        };
        [weakSelf.navigationController pushViewController:supervisionUnitsVC animated:YES];
       
        NSLog(@"选择了监理单位");
    };
    [self.scrollV addSubview:self.supervisorView];
    [self.scrollV addSubview:self.remarkImageView];
}

#pragma mark --- 按钮的点击时间
/**
 发送按钮
 
 */
- (void)submitButtonClick:(UIBarButtonItem *)barButtonItem{
    NSLog(@"%ld",self.progressImgList.count);
    if (self.subbranchView.textField.text.length == 0) {
        [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请选择分部分项"];
        return;
       
    }

    if (self.processhView.textField.text.length == 0) {
        [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请选择工序"];
        return;
    }
    
    if (self.dateView.textField.text.length == 0) {
        [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请选择工序时间"];
        return;
    }
    
    
    
    if (self.progessView.progressLabel.text.length == 0) {
        [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请填写进度"];
        return;
    }
    
    NSDictionary *parameterDic = @{
                                   @"flowId":self.findTreeModel.ids,
                                   @"flowName":self.subbranchView.textField.text,
                                   @"decomposeId":self.procedureModel.procedureId,
                                   @"endDateStr":self.dateView.textField.text,
                                   @"percent": self.percentStr,
                                   @"remark":[self strWithStr:self.remarkStr],
                                   @"quantities":[self strWithStr:self.quantityStr],
                                   @"creator":[[NSUserDefaults standardUserDefaults] objectForKey:kUserID],
                                //   @"progressImgList":[self.progressImgList toReadableJSONString]
                                   };
    //NSLog(@"%@",parameterDic);
    NSString * url = [NSString stringWithFormat:@"%@%@token=%@",kProgressApiBaseUrl,kSaveProgresstUrl,[[NSUserDefaults standardUserDefaults] objectForKey:kToken]];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [SVProgressHUD showSVProgressHUDWithAnimationType:SVProgressHUDAnimationTypeFlat maskType:SVProgressHUDMaskTypeBlack style:SVProgressHUDStyleDark status:@"正在提交数据"];
    
    [manager POST:url parameters:parameterDic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        for (int i = 0; i < self.imageArrM.count; i ++) {
            NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
            formatter.dateFormat=@"yyyyMMddHHmmss";
            NSString *str=[formatter stringFromDate:[NSDate date]];
            NSString *fileName=[NSString stringWithFormat:@"%@.jpg",str];
            UIImage *image = self.imageArrM[i];
            UIImage *compreImage = [image scaleToWidth:1024];
            NSData *imageData = UIImageJPEGRepresentation(compreImage, 0.5);
            [formData appendPartWithFileData:imageData name:@"progressImgList" fileName:fileName mimeType:@"image/png"];
        }
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"code"]integerValue] == 0) {
            
            [SVProgressHUD dismiss];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:responseObject[@"msg"]];;
        }
        NSLog(@"===%@, %@", responseObject[@"msg"],responseObject[@"code"]);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
      [SVProgressHUD showErrorWithStatus:@"网络错误, 请稍候再试"];
    }];
}

/**
 返回按钮*/
- (void)backButton:(UIBarButtonItem *)barButtonItem{
    [self dismissViewControllerAnimated:YES completion:nil];
}

/**
 选择分部分项
 */
-(void)selectedSubbranchView:(UITextField *)textField {
    TKYFindTreeController *treeVC = [[TKYFindTreeController alloc]init];
    __weak typeof(self) weakSelf = self;
    treeVC.selectedBlock = ^(TKYFindTreeModel *nodeModel) {
        textField.text = nodeModel.name;
        // weakSelf.flowNameStr = weakCell.selectedTF.text;
        // weakSelf.flowIdStr = nodeModel.childrenID;
        weakSelf.findTreeModel = nodeModel;
        [self getProcedureListData:nodeModel];
    };
    [self.navigationController pushViewController:treeVC animated:YES];
}

/**
 请求工序列表数据
 */
- (void)getProcedureListData:(TKYFindTreeModel *)findTreeModel{
    NSString *url = [NSString stringWithFormat:@"%@%@token=%@&ifdCode=%@",kApiBaseUrl, kProcedureListUrl, [[NSUserDefaults standardUserDefaults]objectForKey:kToken],findTreeModel.ifdCode];
    
    NSString *urlStringUTF8 = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [KHttpRequestTool GET:urlStringUTF8 parameters:nil success:^(id response) {
        if ([response[@"code"]integerValue] == 0) {
            NSLog(@"==%@",response[@"entityDecomposeEntities"]);
            NSArray *arr = response[@"entityDecomposeEntities"];
            if (arr.count > 0) {
                self.procedureS = [TKYProcedureModel mj_objectArrayWithKeyValuesArray:response[@"entityDecomposeEntities"]];
            }else{
                [SVProgressHUD showWithStatus:@"不存在工序"];
            }
            [SVProgressHUD dismiss];
            
        }else{
            [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请求错误"];
        }
        [SVProgressHUD dismiss];
        
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误, 稍候再试"];
        
    }];
}

- (void)setProcedureS:(NSArray<TKYProcedureModel *> *)procedureS{
    _procedureS = procedureS;
}
/**
 显示工序列表
 */
- (void)showProcessDaoListView:(UIButton *)button selectedTF:(UITextField *)textField{
    //[self getProcedureListData];
    //获取cell的button在view的位置
    CGRect tmp = [ button convertRect:button.bounds toView:self.view];
    DAOListView * daoListView   = [[DAOListView alloc] initWithReferFrame:CGRectMake(kScreenWidth - kWidthScale*60, MyNavBarHeight +kHeightScale *50, kWidthScale *30, kHeightScale *30) titleArray: self.procedureS selected:^(NSInteger selectIndex) {
        //选择工序模型
        TKYProcedureModel *model = self.procedureS[selectIndex];
        textField.text = model.procedureName;
        self.procedureModel = model;
        if ([model.procedureName isEqualToString:@"灌砼"]) {
            [UIView animateWithDuration:0.1 animations:^{
                self.workloadView.frame = CGRectMake(0, self.progessView.kx_bottom, kScreenWidth, kHeightScale *50);
                self.workloadView.titleLabel.kx_height = 25;
                self.workloadView.textField.kx_height = 35;
                self.workloadView.line.kx_height = 0.5;

                self.remarkView.frame = CGRectMake(0, self.workloadView.kx_bottom, kScreenWidth, kHeightScale *100);
                self.addPicButtonView.frame = CGRectMake(0, self.remarkView.kx_bottom +5, kScreenWidth,kHeightScale *50);
                self.remarkImageView.frame = CGRectMake(0, self.addPicButtonView.kx_bottom, kScreenWidth, kHeightScale *160);
                
            }];
        }else{
            [UIView animateWithDuration:0.1 animations:^{
                self.workloadView.frame = CGRectMake(0, self.progessView.kx_bottom, kScreenWidth, kHeightScale *0);
                self.workloadView.titleLabel.kx_height = 0;
                self.workloadView.textField.kx_height = 0;
                self.workloadView.line.kx_height = 0;

                self.remarkView.frame = CGRectMake(0, self.workloadView.kx_bottom, kScreenWidth, kHeightScale *100);
                self.addPicButtonView.frame = CGRectMake(0, self.remarkView.kx_bottom +5, kScreenWidth,kHeightScale *50);
                self.remarkImageView.frame = CGRectMake(0, self.addPicButtonView.kx_bottom, kScreenWidth, kHeightScale *160);
                
            }];
        }
    }];
    daoListView.listViewWidth = kWidthScale *100;
    [daoListView show];
}

#pragma mark---UINavigationControllerDelegate,UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    if (_isSelectedCamera == YES) {
        UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
    }else{
        
    }
    [self.imageArrM addObject:image];
    
    
    // for (UIImage *image  in self.imageArrM) {
    UIImage *compreImage = [image scaleToWidth:1024];
    NSData * imageData = UIImageJPEGRepresentation(compreImage,0.3);
    NSString *imageBase64Str = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    [self.progressImgList addObject:imageBase64Str];
    // }
    self.remarkImageView.imageArr = self.imageArrM;
    [self.remarkImageView.collectionView reloadData];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

//这个地方只做一个提示的功能
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
    if (error) {
        
    }
}

- (void)selectedCameraOrAlbum{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    [alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _isSelectedCamera = NO;
        self.pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:self.pickerController animated:YES completion:nil];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        _isSelectedCamera = YES;
        self.pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:self.pickerController animated:YES completion:nil];
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [self presentViewController:alert animated:YES completion:nil];
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    if (textField == self.workloadView.textField) {
        self.quantityStr = self.workloadView.textField.text;
        
        NSString *URL = [NSString stringWithFormat:@"%@%@token=%@&flowId=%@&quantity=%@",kProgressApiBaseUrl,kgetPercentUrl,[[NSUserDefaults standardUserDefaults]objectForKey:kToken],self.findTreeModel.ids,self.workloadView.textField.text];
        NSString *urlUT = [URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [SVProgressHUD showWithStatus:@"正在计算百分比"];
        [KHttpRequestTool GET:urlUT parameters:nil success:^(id response) {
            NSLog(@"%@",response);
            if ([response[@"code"] integerValue] == 0) {
                NSNumber *percent = response[@"percent"];
                int percentInt = [percent intValue];
                if (percentInt >= 100) {
                    self.progessView.progressLabel.text = @"100%";
                    self.percentStr = self.progessView.progressLabel.text;
                }else{
                    self.progessView.progressValue = [percent integerValue];
                    self.progessView.progressLabel.text = [NSString stringWithFormat:@"%.lf%%",self.progessView.progressValue];
                    self.percentStr = [NSString stringWithFormat:@"%d",percentInt];
                }
                
            }else{
                [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:response[@"msg"]];
            }
            [SVProgressHUD dismiss];
            
        } failure:^(NSError *error) {
            
            NSLog(@"%@",error);
        }];
    }
    //否则返回yes,不限制其他textfield
    return YES;
}

//只输入数字
- (BOOL)validateNumber:(NSString*)number {
    NSCharacterSet *cs;
    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
    NSString *filtered = [[number componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    BOOL basicTest = [number isEqualToString:filtered];
    if(!basicTest)
    {
        [SVProgressHUD showSVProgressImage:nil Duration:2.0 FontSize:16 status:@"请求输入纯数字"];
        //输入了非法字符
        return NO;
    }
    return YES;
}


#pragma mark-- 懒加载
- (NSMutableArray *)imageArrM{
    if (!_imageArrM) {
        _imageArrM = [NSMutableArray array];
    }
    return _imageArrM;
}

- (NSMutableArray *)progressImgList{
    if (_progressImgList == nil) {
        _progressImgList = [NSMutableArray array];
    }
    return _progressImgList;
}

-(UIImagePickerController *)pickerController{
    if (!_pickerController) {
        UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];
        pickerController.delegate = self;
        _pickerController=pickerController;
    }
    return _pickerController;
}

- (TKYRemarkImageView *)remarkImageView{
    if (_remarkImageView == nil) {
        _remarkImageView = [[TKYRemarkImageView alloc]initWithFrame:CGRectMake(0, self.addPicButtonView.kx_bottom, kScreenWidth, kHeightScale *160)];
        __weak typeof(self) weakSelf = self;
        _remarkImageView.seletetedCollectionCellBlock = ^(NSIndexPath *indexPath) {
            [ImageBrowserViewController show:weakSelf type:PhotoBroswerVCTypeModal index:indexPath.item imagesBlock:^NSArray *{
                return weakSelf.imageArrM;
            }];
        };
    }
    return _remarkImageView;
}

- (NSString *)strWithStr:(NSString *)str{
    NSString *newStr = [NSString string];
    if (str.length == 0) {
        newStr = @"";
    }else{
        newStr = str;
    }
    return newStr;
}

- (TKYFindTreeView *)findTreeView{
    if (_findTreeView == nil ) {
        _findTreeView = [[TKYFindTreeView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        __weak typeof(self) weakSelf = self;
        _findTreeView.selectedfindTreeModelBlock = ^(TKYFindTreeModel *findTreeModel) {
            weakSelf.findTreeModel = findTreeModel;
            weakSelf.subbranchView.textField.text = findTreeModel.name;
            [weakSelf getProcedureListData:findTreeModel];
        };
        
        _findTreeView.touchBgView = ^{
            [UIView animateWithDuration:0.25 animations:^{
                  [weakSelf.findTreeView removeFromSuperview];
            }];
        };
    }
    return _findTreeView;
}

- (UIScrollView *)scrollV {
    if (_scrollV == nil) {
        self.automaticallyAdjustsScrollViewInsets = NO;
        _scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight )];
        _scrollV.scrollEnabled = YES;
        //_scrollV.pagingEnabled = YES;
        _scrollV.showsHorizontalScrollIndicator = NO;
        _scrollV.showsVerticalScrollIndicator = YES;
        _scrollV.contentSize = CGSizeMake(0, kScreenHeight +kHeightScale *50);
    }
    return _scrollV;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
